#include "stdafx.h"
#include "save_data.h"
#include "game_path.h"


save_data_x::save_data_x()
{
    m_sPath = game_path::getGamePath();
    game_path::CreateDeepDirectory(m_sPath + SAVE_DATA_PATH);
}

save_data_x::~save_data_x()
{

}

bool save_data_x::Save()
{
    bool bRet = false;
    head.reset();
    body.reset();
    if (_GetPlayerInfo())
    {
        CStringA sSaveDate = CW2A(m_sPath, CP_UTF8);
        sSaveDate += SAVE_DATA_PATH;
        sSaveDate += SAVE_DATA_FILE;
        FILE* pf = fopen(sSaveDate, "wb");
        if (pf)
        {
            size_t size = fwrite(&head, sizeof(head), 1, pf);
            if (size == 1)
            {
                size = fwrite(&body, sizeof(body), 1, pf);
                if (size == 1)
                {
                    bRet = true;
                }
            }
            fclose(pf);
        }
    }
    return bRet;
}

bool save_data_x::Load()
{
    bool bRet = false;
    CStringA sSaveDate = CW2A(m_sPath, CP_UTF8);
    sSaveDate += SAVE_DATA_PATH;
    sSaveDate += SAVE_DATA_FILE;
    FILE* pf = fopen(sSaveDate, "rb");
    if (pf)
    {
        head.reset();
        size_t size = fread(&head, sizeof(head), 1, pf);
        if (size == 1 && head.flag == SAVE_DATA_FLAG && head.ver == SAVE_DATA_VER)
        {
            body.reset();
            size = fread(&body, sizeof(body), 1, pf);
            if (size == 1)
            {
                if (_SetPlayerInfo())
                {
                    bRet = true;
                }
            }
        }
        fclose(pf);
    }
    return bRet;
}

bool save_data_x::_GetPlayerInfo()
{
    body.play_type = em_play_type_1;
    return true;
}

bool save_data_x::_SetPlayerInfo()
{
    return true;
}

